package com.chuhe.starry.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chuhe.common.domain.entity.UserInfoBeauty;
import com.chuhe.common.domain.vo.req.AdminAddBeautyAccountReq;
import com.chuhe.common.domain.vo.req.AdminLoadBeautyAccountReq;
import com.chuhe.starry.mapper.UserInfoBeautyMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 靓号表 服务实现类
 * </p>
 *
 * @author 张楚河
 * @since 2025-05-11
 */
@Service
public class UserInfoBeautyDao extends ServiceImpl<UserInfoBeautyMapper, UserInfoBeauty> {
    /**
     * 查询靓号
     * @Author: 楚河
     * @Date: 2025-05-11 12:05
     */
    public UserInfoBeauty selectEmail(String email) {
        return lambdaQuery()
                .eq(UserInfoBeauty::getEmail, email)
                .one();
    }
    /**
     * 更改状态
     * @Author: 楚河
     * @Date: 2025-05-11 13:48
     */
    public void updateByUid(UserInfoBeauty userInfoBeauty) {
        lambdaUpdate()
                .eq(UserInfoBeauty::getUserId,userInfoBeauty.getUserId())
                .set(UserInfoBeauty::getStatus,userInfoBeauty.getStatus())
                .update();
    }

    /**
     * 查询数量
     * @Author: 楚河
     * @Date: 2025-05-18 11:11
     */
    public int selectCount() {
        return lambdaQuery()
                .count();
    }
    /**
     * 查询靓号 加条件
     * @Author: 楚河
     * @Date: 2025-05-18 11:12
     */
    public List<UserInfoBeauty> selectUserInfoBeautyAccountList(AdminLoadBeautyAccountReq req) {
        return lambdaQuery()
                .eq(StringUtils.isNotBlank(req.getUserIdFuzzy()), UserInfoBeauty::getUserId, req.getUserIdFuzzy())
                .like(StringUtils.isNotBlank(req.getEmail()), UserInfoBeauty::getEmail, req.getEmail())
                .list();
    }
    /**
     * 根据id查询
     * @Author: 楚河
     * @Date: 2025-05-18 11:24
     */
    public UserInfoBeauty selectById(Integer id) {
        return lambdaQuery()
                .eq(UserInfoBeauty::getId, id)
                .one();
    }
    /**
     * 根据  邮箱查询
     * @Author: 楚河
     * @Date: 2025-05-18 11:25
     */
    public UserInfoBeauty selectByEmail(String email) {
        return lambdaQuery()
                .eq(UserInfoBeauty::getEmail, email)
                .one();
    }
    /**
     * 根据userid查询
     * @Author: 楚河
     * @Date: 2025-05-18 11:26
     */
    public UserInfoBeauty selectByUserId(String userId) {
        return lambdaQuery()
                .eq(UserInfoBeauty::getUserId, userId)
                .one();
    }
    /**
     * 修改根据id
     * @Author: 楚河
     * @Date: 2025-05-18 11:28
     */
    public void updateBeautyById(AdminAddBeautyAccountReq beauty, Integer id) {
        lambdaUpdate()
                .eq(UserInfoBeauty::getId, id)
                .set(UserInfoBeauty::getEmail,beauty.getEmail())
                .set(UserInfoBeauty::getUserId,beauty.getUserId())
                .update();
    }
    /**
     * 添加
     * @Author: 楚河
     * @Date: 2025-05-18 11:30
     */
    public void saves(AdminAddBeautyAccountReq beauty) {
        UserInfoBeauty userInfoBeauty = new UserInfoBeauty();
        BeanUtils.copyProperties(beauty, userInfoBeauty);
        save(userInfoBeauty);
    }
    /**
     * 删除靓号
     * @Author: 楚河
     * @Date: 2025-05-18 11:40
     */
    public void delBeautAccount(Integer id) {
        LambdaQueryWrapper<UserInfoBeauty> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserInfoBeauty::getId, id);
        this.remove(wrapper);
    }
}
